{include file="public/layout" /}
<body>
  <link rel="stylesheet" href="__SKIN__/css/page.css" media="all">
   <div class="layui-fluid">
      <div class="layui-card">
        <div class="head-oper">
          <div class="fl">
            <a href="{:url('Channeltype/index')}" class="layui-btn layui-btns-primary  input-btn-back mt5"><i class="layui-icon layui-icon-left"></i></a>
            {eq name="$Think.const.CONTROLLER_NAME.'@channel_add'|is_check_access" value="1"}
            <a data-url="{:url('Field/channel_add', array('channel_id'=>$channel_id))}" data-type="channel_add" class="layui-btn mt5 ">新增内容字段</a>
            {/eq}
          </div>
          <div class="fr ">
            <form action="{:url('Field/channel_index')}" method="get" onsubmit="layer_loading();">
              <div class="fl mt5" >
                {$searchform.hidden|default=''}
                <div class="layui-input-inline w240">
                    <input type="hidden" name="searchopt" value="1">
                    <input type="hidden" name="channel_id" id="channel_id" value="{$channel_id|default='1'}">
                    <input type="text" name="keywords" value="{$Request.param.keywords}" class="layui-input" placeholder="字段搜索...">
                </div>
              </div>
              <div class="layui-input-inline w50 mt5">
                <button class="layui-btn input-btn-search" type="submit"><i class="layui-icon layui-icon-search"></i></button>
              </div>
            </form>
          </div>
        </div>
        <div class="layui-card-body">
          <div class="layui-form layui-border-box layui-table-view house-table" lay-filter="formTest" lay-id="admin-arctype" >
            <div class="layui-table-box">
              <div class="layui-table-body " >
                <table cellspacing="0" cellpadding="0" border="0" class="layui-table layui-form" style="width: 100%" lay-skin="line">
                  <thead >
                    <tr>
                      <th class="w80 tc">
                        <div class="layui-table-cell w80 tc" ><span>ID</span></div>
                      </th>
                      <th> 
                        <div class="layui-table-cell wauto"><span>字段标题</span></div>
                      </th>
                      <th class="w150 tc"> 
                        <div class="layui-table-cell w150 tc"><span>字段名称</span></div>
                      </th>
                      <th class="w130 tc"> 
                        <div class="layui-table-cell w130 tc"><span>字段类型</span></div>
                      </th>
                      <th class="w90 tc"> 
                        <div class="layui-table-cell w90 tc"><span>字段分类</span></div>
                      </th>
                      <th class="w100 tc"> 
                        <div class="layui-table-cell w100 tc"><span>编辑显示</span></div>
                      </th>
                      <th class="w110 tc"> 
                        <div class="layui-table-cell w110 tc"><span>是否必填</span></div>
                      </th>
                      <th class="w80 tc"> 
                        <div class="layui-table-cell w80 tc"><span>排序</span></div>
                      </th>
                      <th class="w250 tc"> 
                        <div class="layui-table-cell w250 tc"><span>操作</span></div>
                      </th>
                    </tr>
                 </thead>
                 <tbody>
                  {empty name="list"}
                    <tr>
                      <td colspan="9" class="no-data tc">
                         没有符合条件的数据
                      </td>
                    </tr>
                  {else/}
                    {foreach name="list" item="vo" key="k" }
                     <tr>
                        <td><div class="layui-table-cell w80 tc"> {$vo.id} </div></td>
                        <td>
                            <div class="layui-table-cell wauto">
                                {if condition="($vo['ifsystem'] eq 1) OR (1 eq $vo['ifmain'])"}
                                    {$vo.title}
                                {else /}
                                    {eq name="$Think.const.CONTROLLER_NAME.'@channel_edit'|is_check_access" value="1"}
                                    <a href="javascript:void(0);" class="eju-event" data-type="channel_edit" data-url="{:url('Field/channel_edit',array('channel_id'=>$channel_id,'id'=>$vo['id']))}">{$vo.title}</a>
                                    {else /}
                                    {$vo.title}
                                    {/eq}
                                {/if}
                            </div>
                        </td>
                        <td>
                            <div class="layui-table-cell w150 tc">
                                {$vo.name}
                            </div>
                        </td>
                        <td>
                            <div class="layui-table-cell w130 tc">
                                {$fieldtypeList[$vo['dtype']]['title']|default='数据错误'}
                            </div>
                        </td>
                        <td>
                            <div class="layui-table-cell w90 tc">
                                {if condition="($vo['ifsystem'] eq 1) OR (1 eq $vo['ifmain'])"}
                                    系统
                                {else /}
                                    自定义
                                {/if}
                            </div>
                        </td>
                        <td>
                            <div class="layui-table-cell w100 tc">
                            {eq name="'Field@ajax_channel_show'|is_check_access" value="1"}
                                {if condition="$vo['ifcontrol'] eq 1"}
                                ———
                                {else /}
                                <input type="checkbox" lay-skin="switch" lay-filter="ifeditable" data-id="{$vo.id}" value="{$vo['ifeditable']}" {eq name="$vo['ifeditable']" value='1'}checked{/eq} lay-text="是|否">
                                {/if}
                            {/eq}
                            </div>
                        </td>
                        <td>
                            <div class="layui-table-cell w110 tc">
                                <input type="checkbox" lay-skin="switch" lay-filter="ifrequire" data-id="{$vo.id}" value="{$vo['ifrequire']}" {eq name="$vo['ifrequire']" value='1'}checked{/eq} lay-text="是|否">
                            </div>
                        </td>
                        <td>
                          <div class="layui-table-cell w80 tc">
                            {if condition="empty($vo['ifsystem'])"}
                                {eq name="$Think.const.CONTROLLER_NAME.'@channel_edit'|is_check_access" value="1"}
                                <input type="text" lay-verify="required|number" value="{$vo.sort_order}" onchange="changeTableVal('channelfield','id','{$vo.id}','sort_order',this);" class="layui-input" onkeyup="this.value=this.value.replace(/[^\d]/g,'');" onpaste="this.value=this.value.replace(/[^\d]/g,'');">
                                {else /}
                                {$vo.sort_order}
                                {/eq}
                            {else /}
                                ——
                            {/if}
                          </div>
                         </td>
                        <td>
                           <div class="layui-table-cell w250 tc right-oper">
                               {if condition="($vo['ifcontrol '] eq 1)"}
                                   {eq name="$Think.const.CONTROLLER_NAME.'@channel_edit'|is_check_access" value="1"}
                                   <a class="layui-btn btn-edit customvar_edit">编辑</a>
                                   {/eq}
                               {else /}
                                   {eq name="$Think.const.CONTROLLER_NAME.'@channel_edit'|is_check_access" value="1"}
                                   <a class="layui-btn btn-edit customvar_edit" data-url="{:url('Field/channel_edit',array('channel_id'=>$channel_id,'id'=>$vo['id']))}" data-type="channel_edit">编辑</a>
                                   {/eq}
                               {/if}
                                {if condition="($vo['ifcontrol'] eq 1) OR (1 eq $vo['ifsystem'])"}
                                    {eq name="$Think.const.CONTROLLER_NAME.'@channel_del'|is_check_access" value="1"}
                                    <a href="javascript:void(0);" class="layui-btn btn-primary" style="color:#ccc; cursor:not-allowed">删除</a>
                                    {/eq}
                                {else /}
                                    {eq name="$Think.const.CONTROLLER_NAME.'@channel_del'|is_check_access" value="1"}
                                    <a href="javascript:void(0);" class="layui-btn btn-primary" data-url="{:url('Field/channel_del', array('channel_id'=>$channel_id))}" data-id="{$vo.id}" data-type="channel_del">删除</a>
                                    {/eq}
                                {/if}
                                <a class="layui-btn btn-primary" href="javascript:void(0);" data-name="{$vo.name}" data-channel_id="{$channel_id|default='0'}" data-dtype="{$vo.dtype}" data-ifmain="{$vo.ifmain}" data-type="copyToClipBoard">标签调用</a>
                           </div>
                        </td>
                      </tr>
                    {/foreach}
                  {/empty}
                  </tbody>
                </table>
        </div>
      </div>
     </div>
     <!--分页-->
      {$pageStr}
     </div>
  </div>
 </div>
  <script>
  layui.config({
    base: '__SKIN__/' //静态资源所在路径
    ,version: '{$version}'
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form'], function(){
    var $ = layui.$
    ,form = layui.form;
      //编辑显示
    form.on('switch(ifeditable)', function(data){
        var obj = data.elem;
        if (obj.checked) {
            data.value = 1;
        } else {
            data.value = 0;
        }
        var ifeditable = data.value;
        var load = layer_loading();
        $.ajax({
            type : 'post',
            url : "{:url('Field/ajax_channel_show')}",
            data : {id:$(obj).attr('data-id'),ifeditable:ifeditable,_ajax:1},
            dataType : 'json',
            success : function(res){
                layer.close(load); //关闭loading
                if(res.code == 1){
                    layer.msg(res.msg, {icon: 1, time:1000}, function(){
                        window.location.reload();
                    });
                }else{
                    showErrorMsg(res.msg);
                }
            }
            ,error: function(e){
                layer.close(load); //关闭loading
                showErrorAlert();
            }
        });
        return false;
    });
    //是否必填
      form.on('switch(ifrequire)', function(data){
          var obj = data.elem;
          if (obj.checked) {
              data.value = 1;
          } else {
              data.value = 0;
          }
          var ifrequire = data.value;
          var load = layer_loading();
          $.ajax({
              type : 'post',
              url : "{:url('Field/ajax_ifrequire')}",
              data : {id:$(obj).attr('data-id'),ifrequire:ifrequire,_ajax:1},
              dataType : 'json',
              success : function(res){
                  layer.close(load); //关闭loading
                  if(res.code == 1){
                      layer.msg(res.msg, {icon: 1, time:1000}, function(){
                          window.location.reload();
                      });
                  }else{
                      showErrorMsg(res.msg);
                  }
              }
              ,error: function(e){
                  layer.close(load); //关闭loading
                  showErrorAlert();
              }
          });
          return false;
      });
    /* 触发事件 */
    var active = {
        channel_add: function(){
            var iframes = layer.open({
                type: 2,
                title: '新增字段',
                fixed: true, //不固定
                shadeClose: false,
                shade: 0.3,
                content: $(this).data('url')
            });
            layer.full(iframes);
        }
        ,channel_edit: function(){
            var iframes = layer.open({
                type: 2,
                title: '编辑字段',
                fixed: true, //不固定
                shadeClose: false,
                shade: 0.3,
                content: $(this).data('url')
            });
            layer.full(iframes);
        }
        ,channel_del: function(){
          var obj = this;
          layer.confirm('<font color="#ff0000">数据将无法恢复</font>，确认删除？', {
              title: false,
              btn: ['确定','取消'] //按钮
            }, function(index){
              layer.close(index);
              var load = layer_loading();
            // 确定
              $.ajax({
                type : 'post',
                url : $(obj).attr('data-url'),
                data : {del_id:$(obj).attr('data-id'),_ajax:1},
                dataType : 'json',
                success : function(res){
                  layer.close(load); //关闭loading
                  if(res.code == 1){
                    layer.msg(res.msg, {icon: 1, time:500}, function(){
                      window.location.reload();
                    });
                  }else{
                    showErrorMsg(res.msg);
                  }
                }
                ,error: function(e){
                  layer.close(load); //关闭loading
                  showErrorAlert();
                }
              })
            }, function(index){
              layer.close(index);
            }
          );
          return false;
        }
        ,copyToClipBoard : function(){
            var obj = this;
            var fieldname = $(obj).attr('data-name');
            var channel_id = $(obj).attr('data-channel_id');
            var dtype = $(obj).attr('data-dtype');
            var ifmain = $(obj).attr('data-ifmain');
            console.log(ifmain);
            var height = '280px';
            var contentdiv = '<div class="dialog_content" style="margin: 0px; padding: 0px;"><dl style="padding:10px 30px;line-height:30px;">';

            if (6 == channel_id) {
                switch(dtype)
                {
                    case 'imgs':
                        {
                            height = '400px';
                            var viewstr = "{eju:diyfield type='"+dtype+"' id='"+fieldname+"' name='$"+"eju.field."+fieldname+"'}\r\n    <img src='{$"+fieldname+".image_url}' />\r\n{/eju:diyfield";
                            contentdiv += '<dd>列表/内容页：</dd>';
                            contentdiv += '<dd><textarea rows="4" cols="60" style="width:470px;height:60px;" class="layui-textarea">' + viewstr + '}</textarea></dd>';
                            var liststr = "{eju:type typeid='栏目ID' id='eyoav' addfields='"+fieldname+"'}\r\n    {eju:diyfield type='"+dtype+"' id='"+fieldname+"' name='$"+"eyoav."+fieldname+"'}\r\n        <img src='{$"+fieldname+".image_url}' />\r\n    {/eju:diyfield"+"}\r\n{/eju:type";
                            contentdiv += '<dd>标签 arclist / list 内调用 <font color="red">(更多简洁调法请参考标签 arclist /list)</font>：</dd>';
                            contentdiv += '<dd><textarea rows="4" cols="60" style="width:470px;height:140px;" class="layui-textarea">' + liststr + '}</textarea></dd>';
                        }
                        break;

                    case 'checkbox':
                        {
                            height = '400px';
                            var viewstr = "{eju:diyfield type='"+dtype+"' id='"+fieldname+"' name='$"+"eju.field."+fieldname+"'}\r\n    {$"+fieldname+".value}\r\n{/eju:diyfield";
                            contentdiv += '<dd>列表/内容页：</dd>';
                            contentdiv += '<dd><textarea rows="4" cols="60" style="width:470px;height:60px;" class="layui-textarea">' + viewstr + '}</textarea></dd>';

                            var liststr = "{eju:type typeid='栏目ID' id='eyoav' addfields='"+fieldname+"'}\r\n    {eju:diyfield type='"+dtype+"' id='"+fieldname+"' name='$"+"eyoav."+fieldname+"'}\r\n        {$"+fieldname+".value}\r\n    {/eju:diyfield"+"}\r\n{/eju:type";
                            contentdiv += '<dd>标签 arclist / list 内调用 <font color="red">(更多简洁调法请参考标签 arclist /list)</font>：</dd>';
                            contentdiv += '<dd><textarea rows="4" cols="60" style="width:470px;height:140px;" class="layui-textarea">' + liststr + '}</textarea></dd>';
                        }
                        break;

                    case 'datetime':
                        {
                            contentdiv += '<dd>列表/内容页：</dd>';
                            contentdiv += '<dd><input type="text" style=" width:470px;margin-bottom:10px;" value="{$'+'eju.field.'+fieldname+'|MyDate=\'Y-m-d H:i:s\',###}" class="layui-input"></dd>';
                            var liststr = "{eju:type typeid='栏目ID' addfields='"+fieldname+"'}\r\n    {$"+"field."+fieldname+"|MyDate=\'Y-m-d H:i:s\',###}\r\n{/eju:type";
                            contentdiv += '<dd>标签 type 属性 addfields 调用：</dd>';
                            contentdiv += '<dd><textarea rows="4" cols="60" style="width:470px;height:60px;" class="layui-textarea">' + liststr + '}</textarea></dd>';
                        }
                        break;

                    default:
                        {
                            contentdiv += '<dd>列表/内容页：</dd>';
                            contentdiv += '<dd><input type="text" style=" width:470px;margin-bottom:10px;" value="{$'+'eju.field.'+fieldname+'}" class="layui-input"></dd>';
                            var liststr = "{eju:type typeid='栏目ID' addfields='"+fieldname+"'}\r\n    {$"+"field."+fieldname+"}\r\n{/eju:type";
                            contentdiv += '<dd>标签 type 属性 addfields 调用：</dd>';
                            contentdiv += '<dd><textarea rows="4" cols="60" style="width:470px;height:60px;" class="layui-textarea">' + liststr + '}</textarea></dd>';
                        }
                        break;
                }

            } else {
                switch(dtype)
                {
                    case 'imgs':
                        {
                            height = '400px';
                            var viewstr = "{eju:diyfield type='"+dtype+"' id='"+fieldname+"' name='$"+"eju.field."+fieldname+"'}\r\n    <img src='{$"+fieldname+".image_url}' />\r\n{/eju:diyfield";
                            contentdiv += '<dd>内容页：</dd>';
                            contentdiv += '<dd><textarea rows="4" cols="60" style="width:470px;height:60px;" class="layui-textarea">' + viewstr + '}</textarea></dd>';
                            var liststr = "{eju:arcview aid='$"+"field.aid' id='eyoav' addfields='"+fieldname+"'}\r\n    {eju:diyfield type='"+dtype+"' id='"+fieldname+"' name='$"+"eyoav."+fieldname+"'}\r\n        <img src='{$"+fieldname+".image_url}' />\r\n    {/eju:diyfield"+"}\r\n{/eju:arcview";
                            contentdiv += '<dd>标签 arclist / list 内调用 <font color="red">(更多简洁调法请参考标签 arclist /list)</font>：</dd>';
                            contentdiv += '<dd><textarea rows="4" cols="60" style="width:470px;height:140px;" class="layui-textarea">' + liststr + '}</textarea></dd>';
                        }
                        break;

                    case 'checkbox':
                        {
                            height = '400px';
                            var viewstr = "{eju:diyfield type='"+dtype+"' id='"+fieldname+"' name='$"+"eju.field."+fieldname+"'}\r\n    {$"+fieldname+".value}\r\n{/eju:diyfield";
                            contentdiv += '<dd>内容页：</dd>';
                            contentdiv += '<dd><textarea rows="4" cols="60" style="width:470px;height:60px;" class="layui-textarea">' + viewstr + '}</textarea></dd>';
                            var liststr = "{eju:arcview aid='$"+"field.aid' id='eyoav' addfields='"+fieldname+"'}\r\n    {eju:diyfield type='"+dtype+"' id='"+fieldname+"' name='$"+"eyoav."+fieldname+"'}\r\n        {$"+fieldname+".value}\r\n    {/eju:diyfield"+"}\r\n{/eju:arcview";
                            contentdiv += '<dd>标签 arclist / list 内调用 <font color="red">(更多简洁调法请参考标签 arclist /list)</font>：</dd>';
                            contentdiv += '<dd><textarea rows="4" cols="60" style="width:470px;height:140px;" class="layui-textarea">' + liststr + '}</textarea></dd>';
                        }
                        break;

                    case 'datetime':
                        {
                            contentdiv += '<dd>内容页：</dd>';
                            contentdiv += '<dd><input type="text" style=" width:470px;margin-bottom:10px;" value="{$'+'eju.field.'+fieldname+'|MyDate=\'Y-m-d H:i:s\',###}" class="layui-input"></dd>';
                            if (1 == ifmain || 2 == ifmain) {
                                contentdiv += '<dd>标签 arclist / list 内调用：</dd>';
                                contentdiv += '<dd><input type="text" style=" width:470px;margin-bottom:10px;" value="{$'+'field.'+fieldname+'|MyDate=\'Y-m-d H:i:s\',###}" class="layui-input"></dd>';
                            } else {
                                var liststr = "eju:field aid='$"+"field.aid' addfields='"+fieldname+"' /";
                                contentdiv += '<dd>标签 arclist / list 内调用：</dd>';
                                contentdiv += '<dd><input type="text" style=" width:470px;margin-bottom:10px;" value="{'+liststr+'}" class="layui-input"></dd>';
                            }
                        }
                        break;

                    default:
                        {
                            contentdiv += '<dd>内容页 -- '+'{$'+'eju.field.'+fieldname+'_unit'+'}为单位：</dd>';
                            contentdiv += '<dd><input type="text" style=" width:470px;margin-bottom:10px;" value="{$'+'eju.field.'+fieldname+'}{$'+'eju.field.'+fieldname+'_unit'+'}" class="layui-input"></dd>';
                            if (1 == ifmain || 2 == ifmain) {
                                contentdiv += '<dd>标签 arclist / list 内调用：</dd>';
                                contentdiv += '<dd><input type="text" style=" width:470px;margin-bottom:10px;" value="{$'+'field.'+fieldname+'}" class="layui-input"></dd>';
                            } else {
                                var liststr = "eju:field aid='$"+"field.aid' addfields='"+fieldname+"' /";
                                contentdiv += '<dd>标签 arclist / list 内调用：</dd>';
                                contentdiv += '<dd><input type="text" style=" width:470px;margin-bottom:10px;" value="{'+liststr+'}" class="layui-input"></dd>';
                            }
                        }
                        break;
                }
            }
            contentdiv += '<dd style="border-top: dotted 1px #E7E7E7; color: #F60;">请将相应标签复制并粘贴到对应模板文件中！</dd></dl></div>'
            layer.open({
                title: '标签调用',
                type: 1,
                skin: 'layui-layer-demo',
                area: ['550px', height], //宽高
                content: contentdiv
            });
        }
    };

    $('.layui-btn,.eju-event').on('click', function(){
      var type = $(this).data('type');
      active[type] && active[type].call(this);
    });

  });

  </script>
{include file="public/footer" /}